import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isEmpty from "lodash/isEmpty";

var _dec, _class;

/**
 * DetailList - 数据审计模态框-详情列表
 * @date: 2019/5/9
 */
import React, { PureComponent } from 'react';
import { Table } from 'antd';
import intl from "../../utils/intl";
import { Bind } from 'lodash-decorators';
/**
 * 数据审计模态框-详情列表
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {Array} dataSource - 版本列表数据
 * @reactProps {Array} comparedData - 对比的数据
 * @return React.element
 */

var DetailList = (_dec = Bind(), (_class = /*#__PURE__*/function (_PureComponent) {
  _inherits(DetailList, _PureComponent);

  var _super = _createSuper(DetailList);

  function DetailList() {
    _classCallCheck(this, DetailList);

    return _super.apply(this, arguments);
  }

  _createClass(DetailList, [{
    key: "renderField",
    value:
    /**
     * 渲染字段名
     * @param {string} text - 字段名
     */
    function renderField(text, displayName) {
      if (displayName) return displayName;
      var comparedData = this.props.comparedData;
      var field = text;

      if (comparedData.length && field) {
        // eslint-disable-next-line eqeqeq
        var targetCol = comparedData.find(function (item) {
          return item.dataIndex == field;
        });

        if (!_isEmpty(targetCol) && targetCol.title) {
          field = targetCol.title;
        }
      }

      return field;
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var dataSource = this.props.dataSource;
      var columns = [{
        title: intl.get('cpaas.common.components.dataAudit.field').d('字段'),
        dataIndex: 'fieldCode',
        width: 100,
        render: function render(text, _ref) {
          var displayName = _ref.displayName;
          return _this.renderField(text, displayName);
        }
      }, {
        title: intl.get('cpaas.common.components.dataAudit.oldValue').d('原值'),
        dataIndex: 'fieldValueOld',
        width: 150,
        render: function render(text, _ref2) {
          var fieldValueOldMeaning = _ref2.fieldValueOldMeaning,
              fieldValueNewMeaning = _ref2.fieldValueNewMeaning;
          var showText = text;

          if (fieldValueOldMeaning && fieldValueNewMeaning) {
            showText = fieldValueOldMeaning;
          }

          return showText;
        }
      }, {
        title: intl.get('cpaas.common.components.dataAudit.newValue').d('现值'),
        dataIndex: 'fieldValueNew',
        width: 150,
        render: function render(text, _ref3) {
          var fieldValueOldMeaning = _ref3.fieldValueOldMeaning,
              fieldValueNewMeaning = _ref3.fieldValueNewMeaning;
          var showText = text;

          if (fieldValueOldMeaning && fieldValueNewMeaning) {
            showText = fieldValueNewMeaning;
          }

          return showText;
        }
      }, {
        title: intl.get('cpaas.common.explain').d('说明'),
        dataIndex: 'remark',
        width: 100
      }];
      return /*#__PURE__*/React.createElement(Table, {
        rowKey: "auditDataLineId",
        bordered: true,
        columns: columns,
        dataSource: dataSource,
        style: {
          marginTop: '50px'
        }
      });
    }
  }]);

  return DetailList;
}(PureComponent), (_applyDecoratedDescriptor(_class.prototype, "renderField", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "renderField"), _class.prototype)), _class));
export { DetailList as default };